<?php
/**
 * @author yupoxiong<i@yufuping.com>
 * @title 首页
 */

namespace app\api\controller;
use app\common\model\User;
use app\common\model\ShopConfig;
use app\api\logic\AdLogic;
use app\api\logic\GoodsLogic;
use app\common\server\UrlServer;
use tools\Crypt;
use think\Request;
use think\Db;
use think\facade\Log;
class IndexController extends ApiBase
{

    protected $authExcept = [
        'home'
    ];

    public function home()
    {
    	//新闻
        $news  = Db::name('article')
            ->where(['delete_time'=>0,'is_notice'=>1,'is_show'=>1])
            ->order('create_time desc')
            ->field('title')
            ->limit(6)
            ->select();
        $news_list=array();
        foreach ($news as $key => $value) {
            $news_list[]=$value['title'];
        }
        //首页顶部banner
        $index_db_banner = AdLogic::lists(1);
        //首页中部banner
        $index_zb_banner = AdLogic::lists(2);
        //福利商城
        $welfaremall_img=ShopConfig::get('welfaremall', 'image');
        //企业集采
        $enterprise_img=ShopConfig::get('enterprise', 'image');
        //品牌故事
        $brandstory_img=ShopConfig::get('brandstory', 'image');

        //活动专区
        $activity_area = Db::name('activity_area')->field('id,name,title,image')->where(['delete_time'=>0,'status'=>1])->select();
        foreach ($activity_area as &$area_item){
            $area_item['image'] = UrlServer::getFileUrl($area_item['image']);
            $area_item['list'] =GoodsLogic::activityGoodsList($area_item['id']);
        }

        $data = [
            'news_list' =>$news_list,
            'index_db_banner'=>$index_db_banner,
            'index_zb_banner'=>$index_zb_banner,
            'welfaremall_img'=>UrlServer::getFileUrl($welfaremall_img),
            'enterprise_img'=>UrlServer::getFileUrl($enterprise_img),
            'brandstory_img'=>UrlServer::getFileUrl($brandstory_img),
            'activity_area'=>$activity_area
        ];
        return success($data);
    }
}